/*  
  -- The Lime II Project -- 

  A tuplespaces-based middleware for coordinating agents and mobile hosts.
  Copyright (C) 2005.
  Gian Pietro Picco, Amy L. Murphy, Lorenzo Bellini.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received this copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/

package lime2;

/**
 * Defines a unique identifier for tuples. TupleID is a "key" for limified tuples, in the sense of relational 
 * databases. Two or more limified tuples can have the same structure and the same values for all their fields, but 
 * the first one. Lime guarantees that the first IField is a globally unique TupleID. Where "globally" means wrt the 
 * whole federated Lime system. TupleIDs are stamped when "out" tuples are limified and inserted into the 
 * LimeTupleSpace.
 * <br>
 * Lime internally translates a null value for a TupleID into "TupleID.UNSPECIFIED"; see LimeTemplate.
 * 
 * @author Gian Pietro Picco
 * @author Amy Murphy
 * @author Lorenzo Bellini
 */

public class TupleID extends LimeItemID
{
 /**
	 * 
	 */
	private static final long serialVersionUID = -6414872214202954050L;

/**
  * Constructor method.
  *
  * @param creationHost the host (LimeServer) on which this item was created 
  * @param n unique numeric identifier (.. must be unique only on the creationHost)
  */
 public TupleID(LimeServerID creationHost, long n) 
 {
  super(creationHost, n);
 }
  
 /**
  * Tests for equality.
  * 
  * @param o Object
  * @return <code>true</code> if the objects match, <code>false</code> otherwise 
  */ 
 public boolean equals(Object o) 
 {
  boolean result = false;	
  if ((o != null) && (o instanceof TupleID))
     {
  	  TupleID tuid = (TupleID) o;
      result = (getNumericIdentifier() == tuid.getNumericIdentifier()) && // faster check first
      	       (getCreationHost().equals(tuid.getCreationHost())); 	           
     }
  return result; 
 }
 
 public int getSize() {
	 return getCreationHost().getHost().getHostName().length() * 2 + 20;
 }
 
}
